package com.guang.test.service2;

import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author liguang
 * @date 2022/8/24 17:27
 */
@Component
public class Person {


    private List<Animal> animals;

    public List<Animal> getAnimals() {
        return animals;
    }

    /**
     * 那么问题是ObjectProvider是怎么来使用的呢？
     * @param objectProvider
     */
    @Autowired
    public void setAnimals(ObjectProvider<Animal> objectProvider) {
        List<Animal> collect = objectProvider.stream().collect(Collectors.toList());
        this.animals = collect;
    }
}
